﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace YouOweMe
{
    public partial class WaitingMoney : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //System.Web.Profile.DefaultProfile.
        }

        protected void DebtsListView_ItemInserting(object sender, ListViewInsertEventArgs e)
        {
            ListView lview = sender as ListView;
            if (lview != null && lview.InsertItem != null)
            {
                DropDownList ddl= lview.InsertItem.FindControl("PeopleDdl") as DropDownList;
                if (ddl != null && !string.IsNullOrEmpty(ddl.SelectedValue))
                {
                    e.Values["IndebtedID"] = ddl.SelectedValue;
                }
            }
        }

        protected void DebtsListView_DataBound(object sender, EventArgs e)
        {
            Literal totalLitteral = DebtsListView.FindControl("TotalLitteral") as Literal;
            if (totalLitteral != null)
                totalLitteral.Text = GetTotalForLoggedUser();
        }
        private string GetTotalForLoggedUser()
        {
            string returnvalue = "&nbsp;&euro;";
            // retrieve user id
            if (Session[Constants.SessionVariables.UserID] != null)
            {
                long userID = Convert.ToInt64(Session[Constants.SessionVariables.UserID]);
                double total = BLL.DebtManager.GetTotalOfLends(userID);
                return string.Format("{0}{1}", total, returnvalue);
            }

            return string.Format("{0}{1}", 0, returnvalue);
        }
    }
}
